﻿using System;
using System.Data;
using System.Data.Common;
using YiYiTong.Rocket.Entity;
using YiYiTong.Rocket.Helper;

namespace YiYiTong.Rocket.DataAccess
{
    public class HuodongDataAccess
    {
        #region 单例模式
        private HuodongDataAccess()
        {
        }

        private static HuodongDataAccess _instance;
        private static readonly object _syncObject = new object();

        public static HuodongDataAccess Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncObject)
                    {
                        if (_instance == null)
                        {
                            _instance = new HuodongDataAccess();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion 单例模式

        /// <summary>
        /// 竞价列表查询
        /// </summary>
        /// <param>1 直播 2 预热 3 爆款 4竞价</param>
        /// <param name="brand_id">品牌id</param>
        /// <param name="category_id">分类id</param>
        /// <param name="selKey">搜索关键字</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageRows"></param>
        /// <returns></returns>
        public DataSet GetHuodongList(long uid, int pageIndex, int pageRows)
        {
            DataSet ds = null;
            try
            {
                DBHelper db = DBFactory.ApiDB;
                string storeName = "proc_huodong_getlist";
                DbCommand Procdbcomm = db.GetStoredProcCommand(storeName);
                db.AddInParameter(Procdbcomm, "@uid", DbType.Int64, uid);
                db.AddInParameter(Procdbcomm, "@pageIndex", DbType.Int32, pageIndex);
                db.AddInParameter(Procdbcomm, "@pageRows", DbType.Int32, pageRows);
                ds = db.ExecuteDataSet(Procdbcomm);
            }
            catch (Exception ex)
            {
                //记录日志
                LogHelper.Error("活动查询-GetHuodongList" + ex.ToString());
            }
            return ds;
        }

        /// <summary>
        /// 活动商品列表
        /// </summary>
        /// <param name="@huodong_id">活动id</param>
        /// <param name="@no_store">0不要缺货 1全部</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageRows"></param>
        /// <returns></returns>
        public DataSet GetGoodsList(long uid, long huodong_id, int no_store, int pageIndex, int pageRows, int isshare)
        {
            DataSet ds = null;
            try
            {
                DBHelper db = DBFactory.ApiDB;
                string storeName = "proc_goods_getlist_huodong";
                DbCommand Procdbcomm = db.GetStoredProcCommand(storeName);
                db.AddInParameter(Procdbcomm, "@uid", DbType.Int64, uid);
                db.AddInParameter(Procdbcomm, "@huodong_id", DbType.Int64, huodong_id);
                db.AddInParameter(Procdbcomm, "@no_store", DbType.Int32, no_store);
                db.AddInParameter(Procdbcomm, "@pageIndex", DbType.Int32, pageIndex);
                db.AddInParameter(Procdbcomm, "@pageRows", DbType.Int32, pageRows);
                db.AddInParameter(Procdbcomm, "@isshare", DbType.Int32, isshare);
                ds = db.ExecuteDataSet(Procdbcomm);
            }
            catch (Exception ex)
            {
                //记录日志
                LogHelper.Error("活动商品查询-proc_goods_getlist_huodong" + ex.ToString());
            }
            return ds;
        }
    }
}
